﻿

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>任务详情</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link href="../../../layuiadmin/style/mystyle.css" rel="stylesheet" />
    <script src="../../../layuiadmin/artdialog/artDialog.js?skins=chrome"></script>
    <script src="../../../layuiadmin/lib/jquery.min.js"></script>
    <script src="../../../layuiadmin/lib/api.js"></script>
    <script src="../../../layuiadmin/lib/common.js"></script>
    <!--编辑器-->
    <link href="../../../layuiadmin/kindeditor/themes/default/default.css" rel="stylesheet" />
    <script src="../../../layuiadmin/kindeditor/kindeditor-all.js"></script>
    <script src="../../../layuiadmin/kindeditor/lang/zh-CN.js"></script>
    <script src="../../../layuiadmin/layui/layui.js"></script>
    <script src="../../../../plugins/common/login.js"></script>
    <script src="../../../layuiadmin/lib/system.js"></script>
    <script>
        //检查服务器是否已登录，没有登录则跳转至登录页。
        sys_islogin();
    </script>
</head>
<body>

    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto" style="padding: 10px 15px !important;">
                <div class="layui-form-item" style="margin-bottom:2px !important;">

                    <div class="layui-inline">
                        <label class="layui-form-label">任务状态</label>
                        <div class="layui-input-inline" style="width:100px !important;">
                            <select name="TASKSTATUS" id="TASKSTATUS" lay-filter="select_status">
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline" style="display:none;" id="approval-style">
                        <button class="layui-btn layuiadmin-btn-list" id="approval-btn">审核</button>
                    </div>

                    <!--<div class="layui-inline">
                <label class="layui-form-label">选择日期</label>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="startTime" placeholder="开始日期">
                </div>
                <div class="layui-form-mid">
                    -
                </div>
                <div class="layui-input-inline">
                    <input type="text" class="layui-input" id="endTime" placeholder="结束日期">
                </div>
            </div>-->

                </div>
            </div>

            <div class="layui-card-body">
                <div class="layui-form" id="layuiadmin-app-form-list" style="padding: 20px 30px 0 0;">
                    <div style="margin-bottom: 45px;">
                        <span style="display:none;" id="ID" name="ID" value=""></span>
                        <input type="hidden" id="ATTACHCODE" name="ATTACHCODE" value="" />

                        <div class="layui-form-item">
                            <label class="layui-form-label">任务标题</label>
                            <div>
                                <span name="TASKNAME" id="TASKNAME" class="layui-form-label-new"></span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">任务负责人</label>
                            <div>
                                <span id="LEADERNAME" type="text" name="LEADERNAME" class="layui-form-label-new"></span>
                                <input type="hidden" id="TASKLEADER" name="TASKLEADER" />
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">任务成员</label>
                            <div>
                                <span id="MEMBERNAME" name="MEMBERNAME" class="layui-form-label-new"></span>
                                <input type="hidden" id="TASKMEMBER" name="TASKMEMBER" />
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">任务审批人</label>
                            <div>
                                <span id="APPROVALNAME" name="APPROVALNAME" class="layui-form-label-new"></span>
                                <input type="hidden" id="APPROVALUSER" name="APPROVALUSER" />
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">任务等级</label>
                            <div>
                                <span name="TASKLEVEL" id="TASKLEVEL" class="layui-form-label-new">
                                </span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">任务标签</label>
                            <div>
                                <span name="TASKTIP" id="TASKTIP" class="layui-form-label-new">
                                </span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">被提醒次数</label>
                            <div>
                                <span name="REMINDTIMES" id="REMINDTIMES" class="layui-form-label-new">
                                </span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <div>
                                <label class="layui-form-label">任务日期</label>
                                <div class="layui-input-inline">
                                    <span class="layui-form-label-new" id="TASKSTARTTIME" name="TASKSTARTTIME"></span>
                                </div>
                                <div class="layui-form-mid">
                                    -
                                </div>
                                <div class="layui-input-inline">
                                    <span class="layui-form-label-new" id="TASKENDTIME" name="TASKENDTIME"></span>
                                </div>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">关联项目</label>
                            <div>
                                <span name="PROJECTID" id="PROJECTID" lay-verify="" class="layui-form-label-new">
                                </span>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">附件</label>
                            <div class="layui-input-inline" style="width:80%;">

                                <ul id="filelist" class="list-inline" style="margin-top:10px;">
                                </ul>
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">任务简介</label>
                            <div class="layui-input-inline" style="width:80%;">
                                <span name="TASKDESC" id="TASKDESC" class="layui-form-label-new"></span>
                            </div>
                        </div>

                    </div>

                </div>
            </div>

            <div class="layui-col-sm12">
                <div class="layui-card">
                    <div class="layui-card-header">
                        加班审批
                    </div>
                    <div class="layui-card-body">
                        <table class="layui-table">
                            <colgroup>
                                <col width="200">
                                <col width="200">
                                <col width="150">
                                <col width="150">
                                <col width="100">
                                <col>
                            </colgroup>
                            <thead>
                                <tr>
                                    <th>开始时间</th>
                                    <th>结束时间</th>
                                    <th>提交人</th>
                                    <th>审批人</th>
                                    <th>时长</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody id="overtime">
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <div class="layui-col-sm12">
                <div class="layui-card">
                    <div class="layui-card-header">
                        任务操作日志
                    </div>
                    <div class="layui-card-body">
                        <table class="layui-table">
                            <colgroup>
                                <col width="250">
                                <col width="200">
                                <col width="150">
                                <col>

                            </colgroup>
                            <thead>
                                <tr>
                                    <th>时间</th>
                                    <th>用户</th>
                                    <th>类型</th>
                                    <th>内容</th>
                                </tr>
                            </thead>
                            <tbody id="approvallog">
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

            <div class="layui-col-sm12">
                <div class="layui-card">
                    <div class="layui-card-header">
                        任务评论
                    </div>
                    <div class="layui-card-body">
                        <table class="layui-table">
                            <colgroup>
                                <col width="180">
                                <col width="120">
                                <col width="100">
                                <col>
                                <col width="70">
                            </colgroup>
                            <thead>
                                <tr>
                                    <th>时间</th>
                                    <th>用户</th>
                                    <th>类型</th>
                                    <th>内容</th>
                                    <th>操作</th>
                                </tr>
                            </thead>
                            <tbody id="commentlist">
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>

        layui.config({
            base: '../../../layuiadmin/' //静态资源所在路径
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'form', 'laydate', 'upload'], function () {
            var $ = layui.$
                , form = layui.form, upload = layui.upload;

            //监听下拉框
            form.on('select(select_status)', function (data) {
                console.log(data)
                $.ajax({
                    url: "/TaskMerber/UpdateTaskStatus",    //请求的url地址
                    dataType: "json",   //返回格式为json
                    //async: false,//请求是否异步，默认为异步，这也是ajax重要特性$("#attachCode").val()
                    data: { id: $("#ID").html(), status: data.value },    //参数值
                    type: "POST",   //请求方式
                    success: function (res) {
                        if (res.flag > 0) {
                            GetTaskLog($("#ID").text());//重新获取日志
                            layer.msg("任务状态成功修改为：" + $("#TASKSTATUS option:selected").text());
                            
                            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                            parent.layui.table.reload('LAY-app-content-list'); //重载表格
                            //parent.layer.close(index); //再执行关闭
                        }
                        else layer.msg(res.message);
                    },
                    error: function (res) {
                        console.log(res);
                        //layer.msg("任务附件获取失败，请联系技术人员");
                    }
                });
            }); 

            //弹出审核弹窗
            $("#approval-btn").on("click", function () {
                layer.open({
                    type: 2
                    , title: '任务审核'
                    , content: 'approval.html'
                    , maxmin: true
                    , area: ['660px', '500px']
                    , success: function (layero, index) {
                        var iframe = window['layui-layer-iframe' + index];
                        // 向子页面的全局函数child_select_user传参
                        iframe.child_fill_data($("#ID").html());
                    }

                });
            });

            
        })



        //接收父页面的数据
        function child_fill_data(data, diclist) {
           
            for (let key in data) {
                $("#" + key.toUpperCase()).html(data[key]);                         
            }
            
            //控制审核按钮的显示,审批人包含当前用户，已审批人不包含当前用户
            if (!common.indexOfContain(data["Y_APPROVALUSERIDS"], "," + user.userid + ",") && common.indexOfContain(data["APPROVALUSER"], "," + user.userid + ",")) {
                
                $("#approval-style").css("display", "inline");
            }
            
            //获取附件
            if (data["ATTACHCODE"]) {
                
                $.ajax({
                    url: "/FileMerber/GetFileAttachCode",    //请求的url地址
                    dataType: "json",   //返回格式为json
                    //async: false,//请求是否异步，默认为异步，这也是ajax重要特性$("#attachCode").val()
                    data: { attachCode: data["ATTACHCODE"]},    //参数值
                    type: "POST",   //请求方式
                    success: function (res) {
                        console.log(res);
                        if (res.flag > 0) {
                            if (res.list.length > 0) {
                                var html = "";
                                for (var i = 0; i < res.list.length; i++) {
                                    html += "<li id=\"" + res.list[i].id + "\"  style=\"height:30px;margin-bottom:10px;\">";
                                    html += "<div class=\"span3\" style=\"font-size: 20px;\">" + res.list[i].filename;
                                    html += "<button onclick=\"deluploadfile('" + res.list[i].id + "')\" class=\"layui-btn layui-btn-normal layui-btn-sm\"' style='float:right;'><i class=\"layui-icon\">&#xe640;</i></button>";
                                    html += "<a target='_blank' href=\"" + res.list[i].filepath + "\" class=\"layui-btn layui-btn-normal layui-btn-sm\"' style='float:right;margin-right:10px;'><i class=\"layui-icon\">&#xe601;</i></a>";
                                    html += "</div>";
                                    html += "</li>";
                                }

                                $("#filelist").append(html);
                            }

                        }
                        else layer.msg("任务附件获取失败，请刷新重试");
                    },
                    error: function (res) {
                        console.log(res);
                        //layer.msg("任务附件获取失败，请联系技术人员");
                    }
                });
            }
            
            //任务字典表
            var level_html = ""; //任务等级
            var tip_html = ""; //任务标签
            var status_html = ""; //任务状态
            var tip_arr = $("#TASKTIP").html() ? $("#TASKTIP").html().split(',') : [];
            for (var i = 0; i < diclist.length; i++) {
                if (diclist[i].type == 1) {
                    status_html += "<option  value='" + diclist[i].code + "'>" + diclist[i].codename + "</option>";
                }
                if (diclist[i].type == 2 && $("#TASKLEVEL").html() == diclist[i].code) {
                    level_html = diclist[i].codename;
                }

            }
            if (tip_arr.length > 0) {
                for (var i = 0; i < diclist.length; i++) {
                    for (var j = 0; j < tip_arr.length; j++) {
                        if (diclist[i].type == 3 && tip_arr[j] == diclist[i].code) {
                            tip_html += diclist[i].codename + ",";
                        }
                    }

                }
            }
            $("#TASKSTATUS").html(status_html);
            $("#TASKLEVEL").html(level_html)
            $("#TASKTIP").html(tip_html);

            $("#TASKSTATUS").val(data["TASKSTATUS"]);

            if (data["PROJECTID"]) {
                //获取项目列表
                $.ajax({
                    url: "/ProjectMerber/GetProjectTitle",    //请求的url地址
                    dataType: "json",   //返回格式为json
                    //async: false,//请求是否异步，默认为异步，这也是ajax重要特性$("#attachCode").val()
                    data: { id: data["PROJECTID"]},    //参数值
                    type: "POST",   //请求方式
                    success: function (res) {
                        $("#PROJECTID").html(res);
                    },
                    error: function (res) {
                        console.log(res);
                        //layer.msg("任务附件获取失败，请联系技术人员");
                    }
                });
            }

            //获取日志
            GetTaskLog(data["ID"]);

            //获取评论
            $.ajax({
                url: "/TaskCommentMerber/GetCommentByID",    //请求的url地址
                dataType: "json",   //返回格式为json
                //async: false,//请求是否异步，默认为异步，这也是ajax重要特性$("#attachCode").val()
                data: { taskid: data["ID"] },    //参数值
                type: "GET",   //请求方式
                success: function (res) {
                    console.log(res);
                    if (res.length > 0) {
                        var html = "";
                        for (var i = 0; i < res.length; i++) {
                            html += "<tr>";
                            html += "<td>" + res[i].CREATETIME + "</td>";
                            html += "<td>" + res[i].REALNAME + "</td>";
                            html += "<td>" + (res[i].TYPE == 1 ? "评论" : "回复评论") + "</td>";
                            html += "<td  style='cursor:pointer;color:blue;' onclick=\"getDetail('" + res[i].ID + "')\">" + (res[i].DETAIL ? res[i].DETAIL : "") + "</td>";
                            html += "<td><a style=\"margin - left: 0px; \" class=\"layui-btn layui-btn-normal layui-btn-xs\" onclick=\"reply('" + res[i].ID + "','" + res[i].RESOURCEID + "','" + res[i].REALNAME+"')\">回复</a></td>";
                            html += "</tr>";
                        }
                        $("#commentlist").html(html);
                    }

                },
                error: function (res) {
                    console.log(res);
                    //layer.msg("任务附件获取失败，请联系技术人员");
                }
            });

            //获取加班申请
            $.ajax({
                url: "/TaskOverTimeMerber/GetOverTimeListByID",    //请求的url地址
                dataType: "json",   //返回格式为json
                //async: false,//请求是否异步，默认为异步，这也是ajax重要特性$("#attachCode").val()
                data: { taskid: data["ID"] },    //参数值
                type: "GET",   //请求方式
                success: function (res) {
                    
                    if (res.length > 0) {
                        var html = "";
                        for (var i = 0; i < res.length; i++) {
                            console.log(common.indexOfContain(res[i].APPROVALUSERID,',' + user.userid + ','));
                            html += "<tr>";
                            html += "<td>" + res[i].STARTTIME + "</td>";
                            html += "<td>" + res[i].ENDTIME + "</td>";
                            html += "<td>" + res[i].REALNAME + "</td>";
                            html += "<td>" + res[i].APPROVALNAME + "</td>";
                            html += "<td  style='cursor:pointer;color:blue;' onclick=\"getOverDetail('" + res[i].ID + "')\">" + res[i].TIMES + "</td>";
                            if (common.indexOfContain(res[i].APPROVALUSERID, ',' + user.userid + ',') && res[i].APPROVALSTATUS == 0) {
                                html += "<td><a style=\"margin - left: 0px; \" class=\"layui-btn layui-btn-normal layui-btn-xs\" onclick=\"overappraisal('" + res[i].ID + "','" + res[i].TASKID + "','" + res[i].REALNAME + "')\">审批</a></td>";
                            }
                            else if (res[i].APPROVALSTATUS != 0) {
                                html += "<td>" + (res[i].APPROVALSTATUS == 1 ? "通过" : "<span style='color:red;'>驳回</span>") + "</td>";
                            }
                            
                            else {
                                html += "<td>无审批权</td>";
                            }
                            
                            html += "</tr>";
                        }
                        $("#overtime").html(html);
                    }

                },
                error: function (res) {
                    console.log(res);
                    //layer.msg("任务附件获取失败，请联系技术人员");
                }
            });
        };

        
        //关闭弹窗
        $("#close").on("click", function () {
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.layer.close(index); //再执行关闭
        });

        //获取任务操作日志
        var GetTaskLog = function (taskid) {
            
            $.ajax({
                url: "/TaskMerber/GetTaskFlowLog",    //请求的url地址
                dataType: "json",   //返回格式为json
                //async: false,//请求是否异步，默认为异步，这也是ajax重要特性$("#attachCode").val()
                data: { taskid: taskid },    //参数值
                type: "GET",   //请求方式
                success: function (res) {

                    if (res.length > 0) {
                        var html = "";
                        for (var i = 0; i < res.length; i++) {
                            html += "<tr>";
                            html += "<td>" + res[i].CREATETIME + "</td>";
                            html += "<td>" + res[i].REALNAME + "</td>";

                            html += "<td>" + (res[i].CONTENT ? res[i].CONTENT : "") + "</td>";
                            html += "<td>" + res[i].DETAIL + "</td>";
                            html += "</tr>";
                        }
                        $("#approvallog").html(html);
                    }

                },
                error: function (res) {
                    console.log(res);
                    //layer.msg("任务附件获取失败，请联系技术人员");
                }
            }); 
        };

        //删除上传文件div
        var deluploadfile = function (id) {
            layer.confirm('确定删除文件吗？', function (index) {
                $.ajax({
                    url: "/FileMerber/DeleteFile",    //请求的url地址
                    dataType: "json",   //返回格式为json
                    async: false,//请求是否异步，默认为异步，这也是ajax重要特性$("#attachCode").val()
                    data: { id: id },    //参数值
                    type: "POST",   //请求方式
                    success: function (res) {
                        if (res.result > 0) {
                            $('#' + id).remove();
                        }
                        else {
                            layer.msg("文件删除失败，请稍后重试");
                        }
                    },

                    error: function (res) {
                        console.log(res);
                        layer.msg("文件删除失败，请联系技术人员");
                    }
                });
                layer.close(index);
            });
        };

        //回复
        var reply = function (commentid,taskid,realname) {
            layer.open({
                type: 2
                , title: '回复评论'
                , content: 'commentform.html'
                , maxmin: true
                , area: ['800px', '700px']
                , success: function (layero, index) {
                    var iframe = window['layui-layer-iframe' + index];
                    // 向子页面的全局函数child_select_user传参

                    iframe.child_fill_data(taskid, 2, commentid, "回复" + realname + "：");
                }

            });
        };

        //查看评论详情
        var getDetail = function (id) {
            layer.open({
                type: 2
                , title: '回复评论'
                , content: 'commentdetail.html'
                , maxmin: true
                , area: ['800px', '700px']
                , success: function (layero, index) {
                    var iframe = window['layui-layer-iframe' + index];
                    // 向子页面的全局函数child_select_user传参

                    iframe.child_fill_data(id);
                }

            });
        }; 

        //加班审批
        var overappraisal = function (id, taskid, realname) {
            layer.open({
                type: 2
                , title: '加班审批'
                , content: 'overtimeapproval.html'
                , maxmin: true
                , area: ['600px', '400px']
                , success: function (layero, index) {
                    var iframe = window['layui-layer-iframe' + index];
                    // 向子页面的全局函数child_select_user传参

                    iframe.child_fill_data(id,taskid);
                    
                }

            });
        };

        //查看加班详情
        var getOverDetail = function (id) {
            layer.open({
                type: 2
                , title: '加班详情'
                , content: 'overtimedetail.html'
                , maxmin: true
                , area: ['800px', '700px']
                , success: function (layero, index) {
                    var iframe = window['layui-layer-iframe' + index];
                    // 向子页面的全局函数child_select_user传参

                    iframe.child_fill_data(id);
                }

            });
        }; 
    </script>
</body>
</html>